<template>
  <div class="AudiResults">
    <el-card>
      <div class="searchBox">
        <el-input size="small" placeholder="请输入内容" v-model="id">
          <template slot="prepend">用户ID</template>
        </el-input>
        提交时间
        <el-date-picker
          size="small"
          v-model="timeArr"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="timeOptions"
          value-format="yyyy-MM-dd"
          @change="focus"
          style="margin-right: 10px"
        >
        </el-date-picker>
        审核状态
        <el-select
          size="small"
          @change="search"
          v-model="status"
          placeholder="请选择审核状态"
        >
          <el-option label="不限" value=""> </el-option>
          <el-option label="已通过" value="1"> </el-option>
          <el-option label="已驳回" value="2"> </el-option>
        </el-select>
        <el-button class="btn" size="small" @click="search">搜 索</el-button>
      </div>
      <div class="typeBox1">
        <el-radio-group
          class="margin"
          size="small"
          v-model="type"
          @change="search"
          fill="#7b94d8"
        >
          <el-radio-button label="1">赠送金币:{{ countGold }}</el-radio-button>
          <el-radio-button label="2"
            >赠送宝石:{{ countDiamond }}</el-radio-button
          >
          <el-radio-button label="3">赠送VIP:{{ countVip }}</el-radio-button>
          <el-radio-button label="4">扣除:{{ countDeduct }}</el-radio-button>
        </el-radio-group>
        <el-button size="small" @click="exportExcel">导出表格</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%; margin-top: 10px"
        :header-cell-style="{ background: '#f5f7fa' }"
      >
        <template slot="empty">
          <el-empty :image-size="200"></el-empty>
        </template>
        <el-table-column prop="create_time" label="提交时间"> </el-table-column>
        <el-table-column prop="id_code" label="用户ID"> </el-table-column>
        <el-table-column label="类型">
          <template slot-scope="scope">
            {{
              scope.row.type == 1
                ? "金币"
                : scope.row.type == 2
                ? "宝石"
                : "VIP"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="number" key="123" label="数量" v-if="type != 3">
        </el-table-column>
        <el-table-column
          prop="vip_time_limit"
          key="1234"
          v-if="type == 3"
          label="时限"
        >
          <template slot-scope="scope">
            {{
              scope.row.vip_time_limit == 1
                ? "月度"
                : scope.row.vip_time_limit == 2
                ? "季度"
                : "年度"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="apply_reason" label="原因"> </el-table-column>
        <el-table-column prop="apply_account" label="申请人"> </el-table-column>
        <el-table-column label="审批信息" type="expand" width="100px">
          <template slot-scope="scope">
            <el-descriptions :column="4" border>
              <el-descriptions-item label="主管审核时间">
                {{ scope.row.charge_approve_time }}
              </el-descriptions-item>
              <el-descriptions-item label="审批主管">
                {{ scope.row.charge_approve_name }}
              </el-descriptions-item>
              <el-descriptions-item label="主管账号">
                {{ scope.row.charge_account }}
              </el-descriptions-item>
              <el-descriptions-item label="主管IP">
                {{ scope.row.charge_ip }}
              </el-descriptions-item>
              <el-descriptions-item label="财务审核时间">
                {{ scope.row.finance_approve_time }}
              </el-descriptions-item>
              <el-descriptions-item label="审批财务">
                {{ scope.row.finance_approve_name }}
              </el-descriptions-item>
              <el-descriptions-item label="财务账号">
                {{ scope.row.finance_account }}
              </el-descriptions-item>
              <el-descriptions-item label="财务IP">
                {{ scope.row.finance_ip }}
              </el-descriptions-item>
            </el-descriptions>
          </template>
        </el-table-column>
        <el-table-column prop="apply_reason" label="结果">
          <template slot-scope="scope">
            <el-tag type="info" v-if="scope.row.last_states == 2">驳回</el-tag>
            <el-tag type="success" v-if="scope.row.last_states == 1"
              >通过</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="reject_reason" label="备注"> </el-table-column>
      </el-table>

      <pagination
        :total="total"
        :page.sync="page"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // 分页
import { adminSystemGiveSystemGiveVerify } from "@/api/AuditManagement";
export default {
  components: { Pagination },
  data() {
    return {
      loading: false,
      type: "1",
      status: "",
      id: "",
      countGold: 0,
      countDiamond: 0,
      countVip: 0,
      countDeduct: 0,
      timeArr: [],
      startTime: "",
      endTime: "",
      timeOptions: {
        disabledDate(platformValue) {
          return platformValue.getTime() > Date.now() - 8.64e6;
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      tableData: [],
      total: 0,
      page: 1,
      pageSize: 10,
      targetArr: [],
      targetId: [],
      dialogVisible: false,
      form: {
        quick: "1",
        reason: "",
      },
    };
  },
  methods: {
    focus() {
      if (!this.timeArr) {
        this.timeArr = [];
      }
      this.startTime = this.timeArr[0];
      this.endTime = this.timeArr[1];
    },
    async getList() {
      this.loading = true;
      const res = await adminSystemGiveSystemGiveVerify({
        verify_type: "3",
        type: this.type,
        page: this.page,
        pageSize: this.pageSize,
        startTime: this.startTime,
        endTime: this.endTime,
        user_id: this.id,
        last_states: this.status,
      });
      this.loading = false;
      if (res.code == 0) {
        this.tableData = res.data.list;
        this.total = parseInt(res.data.count);
        this.countGold = res.data.countGold;
        this.countDiamond = res.data.countDiamond;
        this.countVip = res.data.countVip;
        this.countDeduct = res.data.countDeduct;
      }
    },
    search() {
      this.page = 1;
      this.getList();
    },
    async exportExcel() {
      const res = await adminSystemGiveSystemGiveVerify({
        verify_type: "3",
        type: this.type,
        page: 1,
        pageSize: 1000,
        startTime: this.startTime,
        endTime: this.endTime,
        user_id: this.id,
        last_states: this.status,
      });
      res.data.list.forEach((item) => {
        switch (item.type) {
          case "1":
            item.type = "金币";
            break;
          case "2":
            item.type = "宝石";
            break;
          case "3":
            item.type = "VIP";
            break;
        }
      });
      res.data.list.forEach((item) => {
        switch (item.vip_time_limit) {
          case "1":
            item.vip_time_limit = "月度";
            break;
          case "2":
            item.vip_time_limit = "季度";
            break;
          case "3":
            item.vip_time_limit = "年度";
            break;
        }
      });
      res.data.list.forEach((item) => {
        switch (item.last_states) {
          case "1":
            item.last_states = "通过";
            break;
          case "2":
            item.last_states = "驳回";
            break;
        }
      });
      const head = [
        "提交时间",
        "用户id",
        "类型",
        "数量",
        "时限",
        "原因",
        "申请人",
        "结果",
        "主管审核时间",
        "审核主管",
        "主管账号",
        "主管IP",
        "财务审核时间",
        "审核财务",
        "财务账号",
        "财务IP",
        "备注",
      ];
      const fails = [
        "create_time",
        "id_code",
        "type",
        "number",
        "vip_time_limit",
        "apply_reason",
        "apply_account",
        "last_states",
        "charge_approve_time",
        "charge_approve_name",
        "charge_account",
        "charge_ip",
        "finance_approve_time",
        "finance_approve_name",
        "finance_account",
        "finance_ip",
        "reject_reason",
      ];
      if (res.data.list.length != 0) {
        this.$excel(res.data.list, head, fails, "审核结果");
      }
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style lang="less" scoped>
.AudiResults {
  .searchBox {
    display: flex;
    align-items: center;
    .el-input {
      width: 300px;
      margin-right: 10px;
    }
    .btn {
      margin-left: 10px;
    }
  }
  .margin {
    margin-top: 20px;
  }
  .typeBox1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>